<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
  <head>
    <title></title>  
    <base href="<%=basePath%>">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"> 
	<%@ include file="/common/importJsCss.jsp" %>
 	<script type="text/javascript" id="preJavascript">
$(function(){
	amplify.subscribe( "nodataexample", function() {
    	out( "message","nodataexample topic published!" );
	});
			
	amplify.subscribe( "dataexample", function( data ) {
    	out("data.foo", data.foo); 
	});
			
	amplify.subscribe( "dataexample2", function( param1, param2 ) {
    	out("param1 + param2", param1 + param2);
	});
			
	amplify.subscribe( "priorityexample", function( data ) {
    	out("data.foo", data.foo );
	});
			
	amplify.subscribe( "priorityexample", function( data ) {
    	if ( data.foo === "oops" ) {
        	return false;
    	}
	}, 1 );

	amplify.subscribe( "datacontextexample", $( "p:first" ), function( data ) {
    	this.text( data.exampleText ); // first p element would have "foo bar baz" as text
	});

	$("#btn1").click(function(e){
		amplify.publish( "nodataexample" );
		e.preventDefault();
	});
			
	$("#btn2").click(function(e){
		amplify.publish( "dataexample", { foo: "bar" } );
		e.preventDefault();
	});

	$("#btn3").click(function(e){
		amplify.publish( "dataexample2", "bar", "baz" );
		e.preventDefault();
	});	
					
	$("#btn4").click(function(e){
		amplify.publish( "datacontextexample", { exampleText: "foo bar baz" } );
		e.preventDefault();
	});
			
	$("#btn5").click(function(e){
		amplify.publish( "priorityexample", { foo: "bar" } );
		e.preventDefault();
	});
			
	$("#btn6").click(function(e){
		amplify.publish( "priorityexample", { foo: "oops" } );
		e.preventDefault();
	});	
});
	</script>
  </head>  
  <body>
	<div class="container">
        <div class="page-header">
            <h2>事件注册,调用</h2>
        </div>
<pre class="prettyprint linenums"></pre>
		<a  class="btn" id="btn1">触发事件</a><a  class="btn" id="btn2">传递参数</a><a  class="btn" id="btn3">调用函数</a>
		<a  class="btn" id="btn4">添加文本</a><a  class="btn" id="btn5">优先级</a><a  class="btn" id="btn6">优先级</a>
		<p></p>    
    </div>	
  </body>
</html>
